`Utility::registryGetKeyValue` returns an invalid QVariant should the
key not exist -- which is the case if that switch has never been toggled
before.
--> Fix this by ensuring the QVariant is valid, and only then try to
convert it to a bool.
Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
#ifdef Q_OS_WIN
static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
- if (!isWindows11OrGreater() &&
- Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
- !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
- return true;
+ if (!isWindows11OrGreater() && Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey)) {
+ if (const auto keyVariant = Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme"));
+ keyVariant.isValid() && !keyVariant.toBool()) {
+ return true;
+ }
}
#endif
return isDarkFromStyle();